﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTD2013.Common;
using DTD2013.Entities;
//using tinhchuoi;
using System.Data;
using System.ComponentModel;
using System.Data.SQLite;
using System.Reflection;
using System.Xml.Linq;

namespace DTD2013.DTDLib
{
    public class DataUtilities
    {
        private static SqliteUtilities SqliteHelper = new SqliteUtilities();

        /// <summary>
        /// Get save file path
        /// </summary>
        /// <returns>File path to save</returns>
        public static string GetSaveFilePath()
        {
            string filePathResult = string.Empty;
            SaveFileDialog saveFile = new SaveFileDialog();
            // Default file extension
            saveFile.DefaultExt = Constant.DEFAULT_XML_EXTENSION;
            // Available file extensions
            saveFile.Filter = Constant.XML_FILTER;
            // Adds a extension if the user does not
            saveFile.AddExtension = true;
            // Restores the selected directory, next time
            saveFile.RestoreDirectory = true;
            // Dialog title
            saveFile.Title = Constant.SAVE_FILE_DIALOG_TITLE;
            // Startup directory
            saveFile.InitialDirectory = Application.ExecutablePath;
            // Show the dialog and process the result
            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                filePathResult = saveFile.FileName;
            }
            saveFile.Dispose();
            saveFile = null;
            return filePathResult;
        }

        /// <summary>
        /// Calculate weight of work detail
        /// </summary>
        /// <param name="detailExpression">Work detail expression</param>
        /// <returns>Weight of work detail</returns>
        public static double CalculateWeight(string detailExpression)
        {
            double result = 0;
            object value = detailExpression;
            //tinh_kl calc = new tinh_kl();
            //calc.TINH(ref value);
            //double.TryParse(calc.KQ.ToString(), out result);
            return result;
        }

        /// <summary>
        /// Get object from data row
        /// </summary>
        /// <param name="row">Data row</param>
        /// <param name="type">Type of object return</param>
        /// <returns>Object from data row</returns>
        public static object GetObjectFromDataRow(DataRow row, Type type)
        {
            object objResult = type.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, null);
            foreach (DataColumn column in row.Table.Columns)
            {
                object objTmp = row[column];
                if (objTmp != DBNull.Value)
                {
                    PropertyInfo property = objResult.GetType().GetProperty(column.ColumnName);
                    if (property != null)
                    {
                        property.SetValue(objResult, objTmp, null);
                    }
                }
            }
            return objResult;
        }

        /// <summary>
        /// Get waste by work
        /// </summary>
        /// <param name="congViec">"CongTac" object</param>
        /// <param name="province">Province name</param>
        /// <returns>List of waste</returns>
        public static DataTable GetWasteOfWork(string workCode, string province)
        {
            return SqliteHelper.GetWasteByWorkCode(workCode, province);
        }

        /// <summary>
        /// Get mortar list
        /// </summary>
        /// <returns>Mortar list</returns>
        public static DataTable GetMortarList()
        {
            return SqliteHelper.GetMortarList();
        }

        /// <summary>
        /// Get waste type by waste code
        /// </summary>
        /// <param name="wasteCode">Waste code</param>
        /// <returns>Waste type</returns>
        public static string GetWasteTypeByWasteCode(string wasteCode)
        {
            string electric1 = "3 4 5 6 7 8 9 1";
            string electric2 = "ZE ZF ZG ZH BA 04";
            string electric3 = "305 306 401 402 403 CS1 CS2 CS3 CS4 CS5 " +
                               "CS6 020 040 050 060 080 090 100 120 -01 -02 -03 " +
                               "-04 -05 -06 -07 340 350 360 410 420 430 011 012 " +
                               "013 014 023 024 025 026 027 028 031 032 034 051 " +
                               "052 053 054";
            string water = "ZI ZJ ZK ZL ZM BB BC BD TN";
            string wasteType = string.Empty;
            string s1 = wasteCode.Substring(0, 1);
            string s2 = wasteCode.Substring(0, 2);
            string s3 = wasteCode.Substring(0, 3);
            if (s2.Equals("MA") || s2.Equals("MB"))
                wasteType = WasteType.F.ToString();
            else if (s2.Equals("NC"))
                wasteType = WasteType.E.ToString();
            else if (wasteCode.Equals("VL_KHAC"))
                wasteType = WasteType.A.ToString();
            else if (electric2.IndexOf(s2) >= 0 || electric1.IndexOf(s1) >= 0 || electric3.IndexOf(s3) >= 0)
                wasteType = WasteType.B.ToString();
            else if (s1.Equals("Y") || s1.Equals("W") || water.IndexOf(s2) >= 0)
                wasteType = WasteType.C.ToString();
            else
                wasteType = WasteType.A.ToString();
            return wasteType;
        }

        /// <summary>
        /// Get wastes list of work
        /// </summary>
        /// <param name="congViec">The "CongTac" object</param>
        /// <returns>List wastes of work</returns>
        public static BindingList<DinhMuc> GetWasteListByWork(CongTac congViec, string province, string calculateMethod)
        {
            if (calculateMethod.Equals(Constant.DEFAULT_NORM))
                return SqliteHelper.GetWasteListInNormMethod(congViec, province);
            return SqliteHelper.GetWasteListInProvinceMethod(congViec, province);
        }

        /// <summary>
        /// Get waste by waste code
        /// </summary>
        /// <param name="wasteCode">The waste code</param>
        /// <param name="province">The province</param>
        /// <returns>DinhMuc</returns>
        public static DinhMuc GetWasteByCode(string province, string wasteCode)
        {
            return SqliteHelper.GetWasteByCode(province, wasteCode);
        }

        /// <summary>
        /// Calculate expression
        /// </summary>
        /// <param name="expression">The expression is calculated</param>
        /// <returns>Result of expression</returns>
        public static double CalculateExpression(string expression)
        {
            DataTable dt = new DataTable();
            return Convert.ToDouble(dt.Compute(expression, string.Empty));
        }

        /// <summary>
        /// Get description of symbol
        /// </summary>
        /// <param name="symbol">Symbol name</param>
        /// <returns>Description of symbol</returns>
        public static string GetSymbolDescription(string symbol)
        {
            string description = string.Empty;
            if (symbol.Equals(SymbolCode.A1))
                description = SymbolCodeDescription.A1;
            else if (symbol.Equals(SymbolCode.B1))
                description = SymbolCodeDescription.B1;
            else if (symbol.Equals(SymbolCode.C1))
                description = SymbolCodeDescription.C1;
            else if (symbol.Equals(SymbolCode.Cpvl))
                description = SymbolCodeDescription.Cpvl;
            else if (symbol.Equals(SymbolCode.Cpnc))
                description = SymbolCodeDescription.Cpnc;
            else if (symbol.Equals(SymbolCode.Cpcm))
                description = SymbolCodeDescription.Cpcm;
            else if (symbol.Equals(SymbolCode.Acc))
                description = SymbolCodeDescription.Acc;
            else if (symbol.Equals(SymbolCode.Tt))
                description = SymbolCodeDescription.Tt;
            else if (symbol.Equals(SymbolCode.T))
                description = SymbolCodeDescription.T;
            else if (symbol.Equals(SymbolCode.Ch))
                description = SymbolCodeDescription.Ch;
            else if (symbol.Equals(SymbolCode.Tl))
                description = SymbolCodeDescription.Tl;
            else if (symbol.Equals(SymbolCode.G))
                description = SymbolCodeDescription.G;
            else if (symbol.Equals(SymbolCode.Gtgt))
                description = SymbolCodeDescription.Gtgt;
            else if (symbol.Equals(SymbolCode.Gxdcpt))
                description = SymbolCodeDescription.Gxdcpt;
            else if (symbol.Equals(SymbolCode.Gxdlt))
                description = SymbolCodeDescription.Gxdlt;
            else if (symbol.Equals(SymbolCode.Z))
                description = SymbolCodeDescription.Z;
            else
                description = SymbolCodeDescription.Unknow;
            return description;
        }

        /// <summary>
        /// Get waste list by mortar
        /// </summary>
        /// <param name="macVua">Mac vua code</param>
        /// <param name="dmVua">Dinh muc vua</param>
        /// <param name="province"></param>
        /// <returns></returns>
        public static List<DinhMuc> GetWasteListByMortar(string macVua, double dmVua, string province)
        {
            return SqliteHelper.GetWasteListByMortar(macVua, dmVua, province);
        }

        /// <summary>
        /// Generate random string
        /// </summary>
        /// <param name="lenght">Lenght of string</param>
        /// <returns>Random string</returns>
        public static string GenerateRandomString(int lenght, Random rd)
        {
            string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
            char[] buffer = new char[lenght];
            for (int i = 0; i < lenght; i++)
            {
                buffer[i] = allowedChars[rd.Next(allowedChars.Length)];
            }
            return new string(buffer);
        }

        /// <summary>
        /// Update norm
        /// </summary>
        /// <param name="query">Query string update norm</param>
        public static void UpdateNorm(string query)
        {
            SqliteHelper.ExecuteNonQuery(query);
        }

        /// <summary>
        /// Generate data from standard data
        /// </summary>
        /// <param name="sourceTable">Source table name</param>
        /// <param name="destinationTable">Destination table name</param>
        public static void GenerateDataFromStandardData(string sourceTable, string destinationTable)
        {
            SqliteHelper.GenerateDataFromStandardData(sourceTable, destinationTable);
        }

        /// <summary>
        /// Remove recent file path
        /// </summary>
        /// <param name="filePath">File path</param>
        public static void RemoveRecentFilePath(string filePath)
        {
            SqliteHelper.ExecuteNonQuery(string.Format(QueryString.DELETE_RECENT_FILE_PATH, filePath));
        }

        /// <summary>
        /// Add recent file path to database
        /// </summary>
        /// <param name="filePath">File path</param>
        public static void AddRecentFilePath(string filePath)
        {
            SqliteHelper.ExecuteNonQuery(string.Format(QueryString.ADD_RECENT_FILE_PATH, filePath, 
                                         DateTime.Now.ToString(FormatString.DateTimeFormatString)));
        }

        #region Save file

        /// <summary>
        /// Save tab1 to doc
        /// </summary>
        /// <param name="doc">DTD xml document</param>
        /// <param name="ttDT">Thong tin tab1</param>
        public static void SaveTab1(XDocument doc, ThongTinDT ttDT)
        {
            XElement eTab1 = doc.Element(XMLFile.ROOT).Element(XMLFile.TAB1);
            eTab1.Add(new XElement(Tab1.TEN_DU_AN, ttDT.TenDuAn),
                      new XElement(Tab1.TEN_CT, ttDT.TenCongTrinh),
                      new XElement(Tab1.DD_CT, ttDT.DiaDiemCongTrinh),
                      new XElement(Tab1.TEN_CHU_DT, ttDT.TenChuDauTu),
                      new XElement(Tab1.TEN_NHA_THAU, ttDT.TenNhaThau),
                      new XElement(Tab1.TEN_CHU_TRI, ttDT.TenChuTriLapDauTu),
                      new XElement(Tab1.KSDG, ttDT.KSDG),
                      new XElement(Tab1.HANG, ttDT.Hang),
                      new XElement(Tab1.LOAI_HINH_CHINH, ttDT.LoaiHinhChinh),
                      new XElement(Tab1.CAP_CT, ttDT.CapCongTrinh),
                      new XElement(Tab1.SO_BUOC_TK, ttDT.SoBuocThietKe),
                      new XElement(Tab1.PPT, ttDT.PhuongPhapTinh),
                      new XElement(Tab1.TINH, ttDT.ThuocTinh),
                      new XElement(Tab1.DT_TT, ttDT.DuToanHayThamTra),
                      new XElement(Tab1.NGAY_LAP, ttDT.NgayLap),
                      new XElement(Tab1.NGAY_SUA, ttDT.NgaySua),
                      new XElement(Tab1.MAT_KHAU, ttDT.MatKhau),
                      new XElement(Tab1.HO_TRO_NHAP, ttDT.HoTroNhap));
        }

        /// <summary>
        /// Save tab2 to doc
        /// </summary>
        /// <param name="doc">DTD xml document</param>
        /// <param name="congTacList">Cong tac list</param>
        public static void SaveTab2(XDocument doc, BindingList<CongTac> congTacList)
        {
            XElement eTab2 = doc.Element(XMLFile.ROOT).Element(XMLFile.TAB2);
            // Save treelist cong viec
            foreach (CongTac cv in congTacList)
            {
                XElement eHaoPhis = new XElement(Tab2.HAO_PHIs);
                foreach (DinhMuc hp in cv.HaoPhiCongViecs)
                {
                    eHaoPhis.Add(new XElement(Tab2.HAO_PHI,
                                     new XElement(Tab2.LOAI_HP, hp.LoaiHaoPhi),
                                     new XElement(Tab2.MA_HP, hp.MaVatLieu),
                                     new XElement(Tab2.TEN_HP, hp.TenVatLieu),
                                     new XElement(Tab2.DON_VI, hp.DonVi),
                                     new XElement(Tab2.DINH_MUC, hp.KhoiLuong),
                                     new XElement(Tab2.GIA_THUC, hp.GiaThuc),
                                     new XElement(Tab2.THANH_TIEN, hp.ThanhTien),
                                     new XElement(Tab2.KL_CAN, hp.KhoiLuongCan),
                                     new XElement(Tab2.VC_LENCAO, hp.VanChuyenLenCao)));
                }
                eTab2.Add(new XElement(Tab2.CONG_VIEC,
                                new XElement(Tab2.ID, cv.ID),
                                new XElement(Tab2.PARENTID, cv.ParentID),
                                new XElement(Tab2.STT, cv.STT),
                                new XElement(Tab2.MA_HIEU, cv.MaHieu),
                                new XElement(Tab2.TEN_CV, cv.TenCongViec),
                                new XElement(Tab2.KHOI_LUONG, cv.KhoiLuong),
                                new XElement(Tab2.DON_VI, cv.DonVi),
                                new XElement(Tab2.MAC_VUA, cv.MacVuaChon),
                                new XElement(Tab2.HSVL, cv.HSVL),
                                new XElement(Tab2.HSNC, cv.HSNC),
                                new XElement(Tab2.HSCM, cv.HSCM),
                                new XElement(Tab2.DGVL, cv.DGVL.Value),
                                new XElement(Tab2.DGNC, cv.DGNC.Value),
                                new XElement(Tab2.DGCM, cv.DGCM.Value),
                                new XElement(Tab2.TTVL, cv.TTVL),
                                new XElement(Tab2.TTNC, cv.TTNC),
                                new XElement(Tab2.TTCM, cv.TTCM),
                                new XElement(Tab2.TONG_CONG, cv.TongCong),
                                new XElement(Tab2.DGDD, cv.DGDD),
                                new XElement(Tab2.GDD, cv.GDD),
                                new XElement(eHaoPhis)));
            }
        }

        /// <summary>
        /// Save status price to doc
        /// </summary>
        /// <param name="doc">DTD xml document</param>
        /// <param name="agentPrice">Agent price</param>
        /// <param name="peoplePrice">People price</param>
        /// <param name="machinePrice">Machine price</param>
        /// <param name="totalPrice">Total price</param>
        public static void SaveStatusPrice(XDocument doc, ThongTinDT ttDT)
        {
            XElement eStatus = doc.Element(XMLFile.ROOT).Element(XMLFile.STATUS);
            eStatus.Add(new XElement(StatusPrice.AGENT_PRICE, ttDT.DGVL),
                            new XElement(StatusPrice.PEOPLE_PRICE, ttDT.DGNC),
                            new XElement(StatusPrice.MACHINE_PRICE, ttDT.DGCM),
                            new XElement(StatusPrice.AGENT_PRICE_STATUS, ttDT.TTVL),
                            new XElement(StatusPrice.PEOPLE_PRICE_STATUS, ttDT.TTNC),
                            new XElement(StatusPrice.MACHINE_PRICE_STATUS, ttDT.TTCM),
                            new XElement(StatusPrice.TOTAL_PRICE_STATUS, ttDT.TongCong));
        }

        public static void SaveTab4(XDocument doc, BindingList<ChiPhiXayDung> chiPhiXayDungList)
        {
            XElement eTab4 = doc.Element(XMLFile.ROOT).Element(XMLFile.TAB4);
            foreach (ChiPhiXayDung cpxd in chiPhiXayDungList)
            {
                eTab4.Add(new XElement(Tab4.CHI_PHI_XD,
                            new XElement(Tab4.KY_HIEU, cpxd.KyHieu),
                            new XElement(Tab4.DG_CHI_PHI, cpxd.DienGiaiChiPhi),
                            new XElement(Tab4.CONG_THUC_TINH, cpxd.CongThucTinh),
                            new XElement(Tab4.THANH_TIEN, cpxd.ThanhTien),
                            new XElement(Tab4.GXDCPT, cpxd.Gxdcpt)));
            }
        }

        #endregion

        #region Load file

        public static string GetDtdPassword(string filePath)
        {
            XDocument doc = XDocument.Load(filePath);
            if (doc != null)
            {
                XElement eTab1 = doc.Descendants(XMLFile.TAB1).FirstOrDefault();
                return eTab1.Element(Tab1.MAT_KHAU).Value;
            }
            return string.Empty;
        }

        /// <summary>
        /// Load Tab1 from xml to UI
        /// </summary>
        /// <param name="doc">DTD xml document</param>
        /// <returns>Thong tin DT</returns>
        public static ThongTinDT LoadTab1(XDocument doc)
        {
            XElement eTab1 = doc.Descendants(XMLFile.TAB1).FirstOrDefault();
            ThongTinDT ttDT = new ThongTinDT()
            {
                TenDuAn = eTab1.Element(Tab1.TEN_DU_AN).Value,
                TenCongTrinh = eTab1.Element(Tab1.TEN_CT).Value,
                DiaDiemCongTrinh = eTab1.Element(Tab1.DD_CT).Value,
                TenChuDauTu = eTab1.Element(Tab1.TEN_CHU_DT).Value,
                TenNhaThau = eTab1.Element(Tab1.TEN_NHA_THAU).Value,
                TenChuTriLapDauTu = eTab1.Element(Tab1.TEN_CHU_TRI).Value,
                KSDG = eTab1.Element(Tab1.KSDG).Value,
                Hang = eTab1.Element(Tab1.HANG).Value,
                LoaiHinhChinh = eTab1.Element(Tab1.LOAI_HINH_CHINH).Value,
                CapCongTrinh = eTab1.Element(Tab1.CAP_CT).Value,
                SoBuocThietKe = eTab1.Element(Tab1.SO_BUOC_TK).Value,
                PhuongPhapTinh = eTab1.Element(Tab1.PPT).Value,
                ThuocTinh = eTab1.Element(Tab1.TINH).Value,
                DuToanHayThamTra = eTab1.Element(Tab1.DT_TT).Value,
                NgayLap = Convert.ToDateTime(eTab1.Element(Tab1.NGAY_LAP).Value),
                NgaySua = Convert.ToDateTime(eTab1.Element(Tab1.NGAY_SUA).Value),
                MatKhau = eTab1.Element(Tab1.MAT_KHAU).Value,
                HoTroNhap = Convert.ToBoolean(eTab1.Element(Tab1.HO_TRO_NHAP).Value),
            };

            // Load status price
            XElement eStatusPrice = doc.Descendants(XMLFile.STATUS).FirstOrDefault();
            ttDT.DGVL = Convert.ToDouble(eStatusPrice.Element(StatusPrice.AGENT_PRICE).Value);
            ttDT.DGNC = Convert.ToDouble(eStatusPrice.Element(StatusPrice.PEOPLE_PRICE).Value);
            ttDT.DGCM = Convert.ToDouble(eStatusPrice.Element(StatusPrice.MACHINE_PRICE).Value);
            ttDT.TTVL = Convert.ToDouble(eStatusPrice.Element(StatusPrice.AGENT_PRICE_STATUS).Value);
            ttDT.TTNC = Convert.ToDouble(eStatusPrice.Element(StatusPrice.PEOPLE_PRICE_STATUS).Value);
            ttDT.TTCM = Convert.ToDouble(eStatusPrice.Element(StatusPrice.MACHINE_PRICE_STATUS).Value);
            ttDT.TongCong = Convert.ToDouble(eStatusPrice.Element(StatusPrice.TOTAL_PRICE_STATUS).Value);
            return ttDT;
        }

        /// <summary>
        /// Load tab2 from xml to UI
        /// </summary>
        /// <param name="doc">DTD xml document</param>
        /// <returns>List cong tac</returns>
        public static BindingList<CongTac> LoadTab2(XDocument doc)
        {
            BindingList<CongTac> congTacList = new BindingList<CongTac>();

            XElement eTab2 = doc.Descendants(XMLFile.TAB2).FirstOrDefault();
            IEnumerable<XElement> eCongTacs = eTab2.Elements(Tab2.CONG_VIEC);
            foreach (XElement cv in eCongTacs)
            {
                int? stt = null;
                if (!string.IsNullOrEmpty(cv.Element(Tab2.STT).Value))
                {
                    stt = Convert.ToInt32(cv.Element(Tab2.STT).Value);
                }
                congTacList.Add(new CongTac() 
                {
                    ID = Convert.ToInt32(cv.Element(Tab2.ID).Value),
                    ParentID = Convert.ToInt32(cv.Element(Tab2.PARENTID).Value),
                    STT = stt,
                    MaHieu = cv.Element(Tab2.MA_HIEU).Value,
                    TenCongViec = cv.Element(Tab2.TEN_CV).Value,
                    KhoiLuong = Convert.ToDouble(cv.Element(Tab2.KHOI_LUONG).Value),
                    DonVi = cv.Element(Tab2.DON_VI).Value,
                    MacVuaChon = cv.Element(Tab2.MAC_VUA).Value,
                    HSVL = Convert.ToDouble(cv.Element(Tab2.HSVL).Value),
                    HSNC = Convert.ToDouble(cv.Element(Tab2.HSNC).Value),
                    HSCM = Convert.ToDouble(cv.Element(Tab2.HSCM).Value),
                    DGVL = Convert.ToDouble(cv.Element(Tab2.DGVL).Value),
                    DGNC = Convert.ToDouble(cv.Element(Tab2.DGNC).Value),
                    DGCM = Convert.ToDouble(cv.Element(Tab2.DGCM).Value),
                    TTVL = Convert.ToDouble(cv.Element(Tab2.TTVL).Value),
                    TTNC = Convert.ToDouble(cv.Element(Tab2.TTNC).Value),
                    TTCM = Convert.ToDouble(cv.Element(Tab2.TTCM).Value),
                    TongCong = Convert.ToDouble(cv.Element(Tab2.TONG_CONG).Value),
                    DGDD = Convert.ToDouble(cv.Element(Tab2.DGDD).Value),
                    GDD = Convert.ToDouble(cv.Element(Tab2.GDD).Value),
                    HaoPhiCongViecs = GetWasteListByWorkElement(cv)
                });
            }
            return congTacList;
        }

        /// <summary>
        /// Load Tab4 from xml to UI
        /// </summary>
        /// <param name="doc">DTD xml document</param>
        /// <returns>List chi phi xay dung</returns>
        public static BindingList<ChiPhiXayDung> LoadTab4(XDocument doc)
        {
            BindingList<ChiPhiXayDung> chiPhiXDList = new BindingList<ChiPhiXayDung>();

            XElement eTab4 = doc.Descendants(XMLFile.TAB4).FirstOrDefault();
            IEnumerable<XElement> eChiPhiXDs = eTab4.Elements(Tab4.CHI_PHI_XD);
            foreach (XElement cpxd in eChiPhiXDs)
            {
                chiPhiXDList.Add(new ChiPhiXayDung() 
                {
                    KyHieu = cpxd.Element(Tab4.KY_HIEU).Value,
                    DienGiaiChiPhi = cpxd.Element(Tab4.DG_CHI_PHI).Value,
                    CongThucTinh = cpxd.Element(Tab4.CONG_THUC_TINH).Value,
                    ThanhTien = Convert.ToDouble(cpxd.Element(Tab4.THANH_TIEN).Value),
                    Gxdcpt = Convert.ToDouble(cpxd.Element(Tab4.GXDCPT).Value)
                });
            }

            return chiPhiXDList;
        }

        #endregion

        #region Private method

        private static BindingList<DinhMuc> GetWasteListByWorkElement(XElement eCV)
        {
            BindingList<DinhMuc> haoPhiCVs = new BindingList<DinhMuc>();

            IEnumerable<XElement> eHaoPhis = eCV.Element(Tab2.HAO_PHIs).Elements(Tab2.HAO_PHI);
            foreach (XElement hp in eHaoPhis)
            {
                haoPhiCVs.Add(new DinhMuc() 
                {
                    LoaiHaoPhi = hp.Element(Tab2.LOAI_HP).Value,
                    MaVatLieu = hp.Element(Tab2.MA_HP).Value,
                    TenVatLieu = hp.Element(Tab2.TEN_HP).Value,
                    DonVi = hp.Element(Tab2.DON_VI).Value,
                    KhoiLuong = Convert.ToDouble(hp.Element(Tab2.DINH_MUC).Value),
                    GiaThuc = Convert.ToDouble(hp.Element(Tab2.GIA_THUC).Value),
                    ThanhTien = Convert.ToDouble(hp.Element(Tab2.THANH_TIEN).Value),
                    KhoiLuongCan = Convert.ToDouble(hp.Element(Tab2.KL_CAN).Value),
                    VanChuyenLenCao = Convert.ToDouble(hp.Element(Tab2.VC_LENCAO).Value)
                });
            }
            return haoPhiCVs;
        }

        #endregion
    }
}
